#include "mainwindow.h"
#include "child/LoadDB.h"
#include <QApplication>
#include <QJsonArray>
#include <QJsonDocument>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QString conf = "conf.json";
    QFile file(conf);
    if(!file.open(QIODevice::ReadOnly)){
        QMessageBox::warning(nullptr,"警告","找不到conf.json !");
        return 0;
    }

    QByteArray ba = file.readAll();
    QJsonParseError e;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(ba, &e);

    if(e.error == QJsonParseError::NoError && !jsonDoc.isNull())
    {
        auto &lst = SystemVal::GetInstance()->dbTables;
        auto array = jsonDoc.array();
        for(auto a:array){
            lst.push_back(a.toString());
        }
        qDebug() << lst;
    }else{
        QMessageBox::warning(nullptr,"警告","配置文件异常!");
    }

    LoadDB m_load;
    m_load.show();
    MainWindow w;


    QObject::connect(&m_load,&LoadDB::openMain,[&w,&m_load](){
        w.initUI();
        w.show();
        m_load.close();
    });


    return a.exec();
}
